import torch 
import torch.nn as nn 

from scipy import signal

import scipy
import csv
import os 
import scipy.io as scio
from sklearn import preprocessing
import matplotlib.pyplot as plt 
import numpy as np 

import mne
import pickle
from mne.decoding import UnsupervisedSpatialFilter
import matplotlib.pyplot as plt
import numpy as np
from sklearn.decomposition import PCA, FastICA


def resample_by_interpolation(signal, input_fs, output_fs):

    scale = output_fs / input_fs
    # calculate new length of sample
    n = round(len(signal) * scale)
    # use linear interpolation
    # endpoint keyword means than linspace doesn't go all the way to 1.0
    # If it did, there are some off-by-one errors
    # e.g. scale=2.0, [1,2,3] should go to [1,1.5,2,2.5,3,3]
    # but with endpoint=True, we get [1,1.4,1.8,2.2,2.6,3]
    # Both are OK, but since resampling will often involve
    # exact ratios (i.e. for 44100 to 22050 or vice versa)
    # using endpoint=False gets less noise in the resampled sound
    resampled_signal = np.interp(
        np.linspace(0.0, 1.0, n, endpoint=False),  # where to interpret
        np.linspace(0.0, 1.0, len(signal), endpoint=False),  # known positions
        signal,  # known data points
    )
    return resampled_signal


if __name__ == "__main__":

    

    t1 = torch.tensor([[1, 2, 3], [4 ,5 ,6]], dtype=torch.float32)

    print(torch.mean(t1, dim=0))


